package src.clientSide;

import src.categoryStructures.Categories;
import src.categoryStructures.Category;
import src.dataStructures.*;
import src.messagesToServer.AttemptLogin;
import src.messagesToServer.AttemptLogout;
import src.messagesToServer.CreateNewItem;
import src.messagesToServer.CreateNewUser;
import src.messagesToServer.GetData;
import src.messagesToServer.GetItemCategory;
import src.messagesToServer.GetNameList;
import src.messagesToServer.GetSubnameList;
import src.messagesToServer.RemoveData;
import src.messagesToServer.SetData;
import src.messagesToServer.SetNewPassword;
import src.messagesToServer.SetPermission;
import src.messagesToServer.UnlockLogin;
import src.messagesToServer.setItemCategories;

public class MessageOut {
	
	/**
	 * This method sends a command to the server to create a user
	 * with the given name and password
	 * @param username The created users calling name
	 * @param password The password associated with the user
	 */
	public static void newUser(String username, String password) {
		CCom.handle(new CreateNewUser(username, password));
	}
	
	/**
	 * This method sends a command to the server to create a user
	 * with the given name and password
	 * @param username The created users calling name
	 * @param password The password associated with the user
	 */
	public static void newItem(String itemname) {
		CCom.handle(new CreateNewItem(itemname));
	}
	
	/**
	 * This method sends a command to the server to attempt to login
	 * @param username The user name for the login
	 * @param password The password associated with the user
	 */
	public static void login(String username, String password) {
		CCom.handle(new AttemptLogin(username, password));
	}
	
	/**
	 * This method sends a command to the server to logout
	 */
	public static void logout() {
		CCom.handle(new AttemptLogout());
	}
	
	/**
	 * This method sends a command to the server to replace the password if
	 * the password is correct
	 * @param username The user name for the login
	 * @param password The password associated with the user
	 * @param newpassword The new password to replace the current
	 */
	public static void newPassword(String username, String password, String newpassword) {
		CCom.handle(new SetNewPassword(username, password, newpassword));
	}
	
	/**
	 * This method sends a command to the server to unlock a locked users login
	 * @param userid The ID of the user to unlock
	 */
	public static void unlock(int userid) {
		CCom.handle(new UnlockLogin(userid));
	}
	
	/**
	 * This method sends a command to the server to return the data object associated
	 * with the given ID
	 * @param dataid The reference ID of the desired data
	 */
	public static void getData(int dataid) {
		CCom.handle(new GetData(dataid));
	}
	
	/**
	 * This method sends a command to the server to alter the stored data associated with 
	 * this data object
	 * @param data The new data object
	 */
	public static void setData(Data data) {
		CCom.handle(new SetData(data));
	}
	
	/**
	 * This method sends a command to the server to delete the data at the given ID
	 * @param dataid The ID of the data to delete
	 */
	public static void removeData(int dataid) {
		CCom.handle(new RemoveData(dataid));
	}
	
	/**
	 * This method sends a command to the server to change the permission of the given ID
	 * @param dataid The ID of the object to change
	 * @param permission The new permission level to set
	 */
	public static void setPermission(int dataid, int permission) {
		CCom.handle(new SetPermission(dataid, permission));
	}
	
	/**
	 * This method sends a command to the server to return a list of items for the given catagory
	 * @param categories The categories to include.  UNSPECIFIED for no preference
	 * @param start The start position of the list, counting backwards.  Set first page at 0
	 * @param length The length of the list
	 */
	public static void getItemCategory(Category categories, int start, int length) {
		CCom.handle(new GetItemCategory(categories, start, length));
	}
	
	/**
	 * This method changes the categories in the desired item
	 * @param itemid The ID of the item to change
	 * @param categories The new categories to subsitute
	 */
	public static void setItemCategory(int itemid, Categories categories) {
		CCom.handle(new setItemCategories(itemid,categories));
	}
	
	/**
	 * This method sends a command to the server to return a list of users alphabetically sorted
	 * @param start The string marking the beginning of the list
	 * @param length The length of the list
	 * @param type The type, user or item, of the data requested
	 */
	public static void getNameList(String start, int length, DataType type) {
		CCom.handle(new GetNameList(start, length, type));
	}
	
	/**
	 * This method sends a command to the server to return a list of all users preceded with 
	 * the given substring
	 * @param start The substring to search for
	 * @param maxlength The maximum length for the list returned
	 * @param type The type, user or item, of the data requested
	 */
	public static void getUserSubList(String start, int maxlength, DataType type) {
		CCom.handle(new GetSubnameList(start, maxlength, type));
	}
	
	/**
	 * This method sends the second to last redo-able message.  The equivalent of going to the last page.  
	 */
	public static void backMessage() {
		CCom.back();
	}
	
	/**
	 * This method sends the last redo-able message.  The equivalent of reloading the page.  
	 */
	public static void reloadMessage() {
		CCom.reload();
	}
	
	/**
	 * This method sends the next redo-able message.  The equivalent of going to the next page.  
	 */
	public static void forwardMessage() {
		CCom.forward();
	}
	
}
